{literal}
<h1>Coding standard</h1>

Following coding standards is one of the easiest way for everybody to understand everybody's code.<br />
Here's the golden rule: <b>Imitate the existing Domframework code</b>.<br />
<br />
You might want to get familiar with this <a href="http://www.dagbladet.no/development/phpcodingstandard/">document</a>. It has alot of good ideas in it. 
(NB! Notice that given coding format rules in that document <span style="color:red">doesn't apply for Dom framework!</span>. There are just many good ideas and thoughts!)<br />

<h1> Names </h1>

<a name="descriptive"></a>
<h3> Make Names Fit </h3>

Names are the heart of programming. In the
past people believed knowing someone's true name gave them magical
power over that person. If you can think up the true name for something,
you give yourself and the people coming after power over the code.
Don't laugh! <p>

A name is the result of a long deep thought process about
the ecology it lives in. Only a programmer who understands the system as a whole
can create a name that "fits" with the system. If the name is appropriate
everything fits together naturally, relationships are clear, meaning is derivable,
and reasoning from common human expectations works as expected. </p><p>

If you find all your names could be Thing and DoIt then you should probably
revisit your design. </p><p>

</p><h3> <b>Class Names</b> </h3>

<ul>
<li> Name the class after what it is. If you can't think of what it is that is a clue
     you have not thought through the design well enough.
</li><li> Compound names of over three words are a clue your design may be confusing
     various entities in your system. Revisit your design. Try a CRC card session
     to see if your objects have more responsibilities than they should.
</li><li> Avoid the temptation of bringing the name of the class a class derives from into the
     derived class's name. A class should stand on its own. It doesn't
     matter what it derives from.
</li><li> Suffixes are sometimes helpful. For example, if your system uses agents then naming
     something DownloadAgent conveys real information.
</li></ul>

<h3> Method and Function Names </h3>

<ul>
<li> Usually every method and function performs an action, so the name
     should make clear what it does: checkForErrors()
     instead of errorCheck(), dumpDataToFile() instead of dataFile().
     This will also make functions and data objects more distinguishable.
</li><li> Suffixes are sometimes useful:
     <ul>
     <li> <i>Max</i> - to mean the maximum value something can have.
     </li><li> <i>Count</i> - the current count of a running count variable.
     </li><li> <i>Key</i> - key value.
     </li></ul><p>
     For example: RetryMax to mean the maximum number of retries, RetryCount to
     mean the current retry count. </p><p>
</p></li><li> Prefixes are sometimes useful:
     <ul>
     <li> <i>Is</i> - to ask a question about something. Whenever someone sees <i>Is</i> they will know it's a question.
     </li><li> <i>Get</i> - get a value.
     </li><li> <i>Set</i> - set a value.
     </li></ul><p>
     For example: IsHitRetryLimit. </p><p>
</p></li></ul>
<p>

<a name="noabbrev"></a>
</p><h3> No Upper Case Abbreviations </h3>

<ul>
  <li> When confronted with a situation where you could use an all upper case
    abbreviation instead use an initial upper case letter followed by all lower
    case letters. No matter what.<br>
    <br>
    Do use: GetHtmlStatistic. <br>
    Do not use: GetHTMLStatistic.<br>

</li></ul>



<h1>Rules</h1>

Indentation is done by using tabulation:<br />
<pre class="code">&lt;?php
class MyClass {
	
	public $name;

	public function bar() {
		Something::make();
	}
}
?&gt;</pre>

Formating if statements (others also like foreach, for etc)
<pre class="code">&lt;?php
// incorrect
if ($myVar == getRequestValue($name))
{
	doSomething();
}

// correct
if( $myVar == getRequestValue($name) ) {
	doSomething();
}

// allowed
if( $myVar == getRequestValue($name) )
	doSomething();
	
// allowed, but it must be short and easy to understand!
$value = $myVar == getRequestValue($name) ? doSomething() : doSomethingElse();

?&gt;</pre>

Use camelCase, not underscores, for variable, function and method names:<br>
<ul>
    <li>Good: function makeCoffee()</li>
    <li>Bad: function MakeCoffee()</li>
    <li>Bad: function make_coffee()</li>
</ul>
Braces always go on the starting line. Ending braces go to new line.<br>
<br>
Avoid evaluating variables within strings, instead opt for concatenation:<br>
<br>
<pre class="code">&lt;?php
$string = 'something';
$newString = "$string is awesome!";  // very bad!
$newString = $string . ' is awesome!'; // better
$newString = sprintf('%s is awesome', $string); // for exception messages and strings with a lot of substitutions
?&gt;</pre>

Use lowercase PHP native typed constants: false and true. <br />
NULL is used as uppercase. <br/>
The same goes for array(). <br />
At the opposite, always use uppercase strings for user defined constants, like define('MY_CONSTANT', 'foo/bar'). Better, try to always use class constants:
<br />
<pre class="code">&lt;?php
class sfCoffee {
	const HAZ_SUGAR = true;
}
debug( sfCoffee::HAZ_SUGAR );
?&gt;</pre>

To check if a variable is null:

<pre class="code">&lt;?php
if ( $coffee === NULL ) {
	echo 'I can haz coffee';
}
?&gt;</pre>

When comparing a variable to a string, put the string first and use type testing when applicable:

<pre class="code">&lt;?php
if ( 1 === $variable ) // good

if( $variable === 1 ) // allowed
?&gt;</pre>

Use PHP type hinting in functions and method signatures:

<pre class="code">&lt;?php
public function notify( MyClass $event, array $someArray ) {
  // ...
}
?&gt;</pre>
All function and class methods should have their phpdoc own block:<br />
<pre class="code">&lt;?php
/**
 * Short description goes here
 *
 * Long description goes here
 * 
 * @package DomFramework
 * @subpackage Sub
 * @author Dom Framework
 */
class MyClass {
	/**
	 * Short description goes here
	 *
	 * Long description goes here
	 *
	 * @var String
	 */
	public $name;
	
	/**
	 * Short description goes here
	 *
	 * Long description goes here
	 *
	 * @param String $argument
	 * @return Int
	 */
	public function myMethod( $argument ) {
		return 10;
	}
}
?&gt;</pre>
{/literal}